﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace daStaticAnalyser.Analysers
{
    using daStaticAnalyser;
    using daBase.Objects;
    using daBase.Analyser;
    using daSyntaxAnalyser;
    using daSyntaxAnalyser.SyntaxTree;

    [AnalyserDefaultSettings("Метрика Шнейдевинда", "test", 0, "test")]
    class ShneidevindAnalyzer : BaseStaticAnalyser
    {

        protected override void DoAnalyse(SyntaxTreeArgs e)
        {
            String MethodName = "";
            if (CheckMethod_GetName(e, out MethodName))
            {
                OuterMethodElement Method = e.Element as OuterMethodElement;
                ControlGraph CG = new ControlGraph();
                CG.Build(Method.Body.Statement);

                int A = 1;
                foreach (var elt in CG.Elements)
                {
                    if(elt.Next.Count>0)
                        A *= elt.Next.Count;
                }
                AddMetric("Метрика Шнейдевинда", A,
                    MethodName,
                    Method.StartInfo.File,
                    Method.StartInfo.Line);
            }
        }
    }

    
}
